package com.jason.quectel0805.activities;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;

import com.jason.quectel0805.R;
import com.jason.quectel0805.adapters.MyViewPagerAdapter;

import java.util.ArrayList;
import java.util.List;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

public class MyViewPagerActivity extends AppCompatActivity {
    private ViewPager viewPager;
    private List<View> list = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_view_pager);
        //初始化viewpager
        viewPager = findViewById(R.id.viewpager_show);
        //    创建adapter适配器
        MyViewPagerAdapter myViewPagerAdapter = new MyViewPagerAdapter(list);
        //将viewpager和adapter进行绑定
        viewPager.setAdapter(myViewPagerAdapter);
        //更新数据源
        LayoutInflater inflater = LayoutInflater.from(this);
        View view1 = inflater.inflate(R.layout.activity_splash, null);
        View view2 = inflater.inflate(R.layout.activity_main, null);
        View view3 = inflater.inflate(R.layout.activity_net, null);
        View view4 = inflater.inflate(R.layout.activity_second, null);
        View view5 = inflater.inflate(R.layout.activity_third, null);
        list.add(view1);
        list.add(view2);
        list.add(view3);
        list.add(view4);
        list.add(view5);
        myViewPagerAdapter.notifyDataSetChanged();
    }
}